package com.example.sfm.controller;


import com.example.sfm.constant.MessageConstants;
import com.example.sfm.pojo.dto.FeedbackDto;
import com.example.sfm.pojo.dto.FeedbackQueryDto;
import com.example.sfm.result.Result;
import com.example.sfm.service.IFeedbackService;
import com.example.sfm.utils.ThreadLocalUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sfm
 * @since 2025-03-07
 */
@RestController("userFeedbackController")
@RequestMapping("/user/feedbacks")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "用户反馈相关接口", description = "用户反馈相关接口")
public class FeedbackController {
    private final IFeedbackService feedbackService;

    /**
     * 创建反馈
     */
    @PostMapping("/create")
    @Operation(summary = "创建反馈", description = "创建反馈")
    public Result<?> createFeedback(@RequestBody @Validated @Parameter(description = "反馈信息") FeedbackDto dto) {
        log.info("创建反馈: {}", dto);
        feedbackService.createFeedback(dto);
        return Result.success(MessageConstants.ADD_OK);
    }

    /**
     * 分页查询反馈
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询反馈", description = "分页查询反馈")
    public Result<?> listFeedbacks(@ParameterObject FeedbackQueryDto dto) {
        dto.setUserId(ThreadLocalUtil.getId());
        log.info("查询反馈列表: {}", dto);
        return Result.success(feedbackService.listFeedbacks(dto), MessageConstants.SELECT_OK);
    }
}
